﻿Imports System.Data.SqlClient
Imports PhDir.DAL
Imports PhDir.Model
Imports PhDir.Repository
Imports System.Collections.Generic

Namespace Repository.Department

    Public Class SearchDepartmentById
        Implements ISearch(Of Model.Department, String)

        Public Function Search(departmentId As String) As List(Of Model.Department) _
            Implements ISearch(Of Model.Department, String).Search

            Dim sqlDataReader As SqlDataReader = Nothing
            Dim departments As List(Of Model.Department) = New List(Of Model.Department)

            Using dbConnection = New DbConnection(DbContext.PhoneContext)
                dbConnection.AddParameter("@DepartmentId", departmentId)
                dbConnection.CommandText = StoredProceduresName.GetDepartmentById
                dbConnection.CommandType = CommandType.StoredProcedure
                sqlDataReader            = dbConnection.ExecuteReader()

                While sqlDataReader.Read()
                    departments.Add(New Model.Department With {.DepartmentId   = sqlDataReader("DepartmentId"),
                                                               .DepartmentName = sqlDataReader("Name")})
                End While
            End Using

            Return departments
        End Function

    End Class

End Namespace
